﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Honestysoft.Financing.Model;
using Honestysoft.Baseframework.WebUI;
using System.IO;

namespace Honestysoft.Financing.WebUI.Module.Audit
{
    public class AuditUtils
    {
        /// <summary>
        /// 页面之间传输树模块的参数名
        /// </summary>
        public const string ParamName_AuditTreeModule = "TreeModule";
        /// <summary>
        /// 页面之间传输树节点类型的参数名
        /// </summary>
        public const string ParamName_AuditNodeType = "NodeType";

        /// <summary>
        /// 项目树模块
        /// </summary>
        public enum TreeModule
        {
            /// <summary>
            /// 合同库
            /// </summary>
            Contract,
            /// <summary>
            /// 变更
            /// </summary>
            Change,
            /// <summary>
            /// 支付
            /// </summary>
            Payment,
            /// <summary>
            /// 初始化确定
            /// </summary>
            InitConfirm,
            /// <summary>
            /// 资料接收表
            /// </summary>
            DocReceive
        }
        /// <summary>
        /// 项目树节点类型
        /// </summary>
        public enum AuditTreeNodeType
        {
            /// <summary>
            /// 根节点
            /// </summary>
            Batch,
            /// <summary>
            /// 项目
            /// </summary>
            Project,
            /// <summary>
            /// 合同
            /// </summary>
            Contract,
            /// <summary>
            /// 审核表
            /// </summary>
            AuditTable
        }

        /// <summary>
        /// 格式化资料接收时间
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static string FormatRecDate(DateTime date)
        {
            string ret = string.Format("{0:yyyy年M月d日}（周", date);

            switch (date.DayOfWeek)
            {
                case DayOfWeek.Monday:
                    ret += "一";
                    break;
                case DayOfWeek.Tuesday:
                    ret += "二";
                    break;
                case DayOfWeek.Wednesday:
                    ret += "三";
                    break;
                case DayOfWeek.Thursday:
                    ret += "四";
                    break;
                case DayOfWeek.Friday:
                    ret += "五";
                    break;
                case DayOfWeek.Saturday:
                    ret += "六";
                    break;
                case DayOfWeek.Sunday:
                    ret += "日";
                    break;
                default:
                    break;
            }
            ret += "）";
            return ret;
        }

        /// <summary>
        /// 导出到Excel
        /// </summary>
        /// <param name="id"></param>
        public static string ExportToExcel(string id)
        {
            Bu_AuditTable atObj = new Honestysoft.Financing.BusinessLogic.Audit("").GetAuditTable(id);
            string templateFileName = HttpContext.Current.Server.MapPath(string.Format(Globals.Home + "Module/Audit/ExcelTemplate/AT_{0}.xlsx", atObj.TableType));
            string outPutDir = string.Format(Globals.Home + "Reports/{0}", atObj.BatchNo);
            string outPutFile = HttpContext.Current.Server.MapPath(string.Format("{0}/{1}.xlsx", outPutDir, atObj.Code));
            if(!Directory.Exists(HttpContext.Current.Server.MapPath(outPutDir)))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(outPutDir));
            }
            if (File.Exists(outPutFile))
            {
                File.Delete(outPutFile);
            }
            Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper = new BaseLibrary.Common.ExcelHelper(templateFileName, outPutFile);

            try
            {
                OutPutHeader(atObj, excelHelper);                
                int totalAddCount = 0;
                totalAddCount += OutPutInvoice(atObj, excelHelper);
                totalAddCount += OutPutPart2(atObj, excelHelper, totalAddCount);
                OutPutPart3(atObj, excelHelper, totalAddCount);
                OutPutPart4(atObj, excelHelper, totalAddCount);
                OutPutPart5(atObj, excelHelper, totalAddCount);
                //Modify by 2012-9-25 A,B表第六大项最后部分添加了3行，故后续所有都必须添加3行
                OutPutPart6(atObj, excelHelper, totalAddCount);
                totalAddCount += OutPutPart7(atObj, excelHelper, totalAddCount);
                OutPutPart8(atObj, excelHelper, totalAddCount);
                OutPutPart9(atObj, excelHelper, totalAddCount);
                OutPutPart10(atObj, excelHelper, totalAddCount);
                OutPutPartWorkflow(atObj, excelHelper, totalAddCount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                excelHelper.OutputExcelFile();
                excelHelper.Quit();
            }
            return string.Format("{0}/{1}.xlsx", outPutDir, atObj.Code);
            //string swfFileName = string.Format("{0}/{1}.swf", outPutDir, atObj.Code);
            //ExportToSWF(outPutFile, HttpContext.Current.Server.MapPath(swfFileName));
            //return swfFileName;
        }

        public static void ExportToSWF(string oldFileName,string outPutFileName)
        {
            System.Diagnostics.Process pc = new System.Diagnostics.Process();
            string flashPrinterPath = HttpContext.Current.Server.MapPath(Globals.Home + "FlashPaper/FlashPrinter.exe");
            pc.StartInfo.FileName = flashPrinterPath;//安装路径
            if (File.Exists(outPutFileName))
            {
                File.Delete(outPutFileName);
            }
            pc.StartInfo.Arguments = string.Format("{0} -o {1}", oldFileName, outPutFileName);
            pc.StartInfo.CreateNoWindow = true;
            pc.StartInfo.UseShellExecute = false;
            pc.StartInfo.RedirectStandardInput = false;
            pc.StartInfo.RedirectStandardOutput = false;
            pc.StartInfo.RedirectStandardError = true;
            pc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            pc.Start();
            pc.WaitForExit();
            pc.Close();
            pc.Dispose();
        }

        /// <summary>
        /// 输出表头（A,B,C都一样）
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        private static void OutPutHeader(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper)
        {
            //表头、一、
            //批次
            excelHelper.SetCells(1, 2, 2, "审核批次：" + atObj.BatchNo.ToString());
            //编号
            excelHelper.SetCells(1, 2, 8, atObj.Code);
            //项目名称
            excelHelper.SetCells(1, 4, 4, atObj.ProjectName);
            //项目代码
            excelHelper.SetCells(1, 4, 7, atObj.ProjectCode);
            //项目单位
            excelHelper.SetCells(1, 5, 4, atObj.Owner971Name);
            //建设单位
            if (atObj.DOwners != null && atObj.DOwners.Count > 0)
            {
                string downerStr = "";
                foreach (Bu_AuditTable_DOwner item in atObj.DOwners)
                {
                    if (downerStr != "") { downerStr += "\n"; }
                    downerStr += item.CompanyName;
                }
                excelHelper.SetCells(1, 5, 7, "建设单位：" + atObj.OwnerName + "\n委托代建单位：" + downerStr);
                excelHelper.SetRowHeight(5, 5, 15 + 15 * atObj.DOwners.Count);
            }
            else
            {
                excelHelper.SetCells(1, 5, 7, atObj.OwnerName);
            }
            //if (string.IsNullOrEmpty(atObj.DOwnerName))
            //{
            //    excelHelper.SetCells(1, 5, 7, atObj.OwnerName);
            //}
            //else
            //{
            //    excelHelper.SetCells(1, 5, 7, "建设单位：" + atObj.OwnerName + "\n委托代建单位：" + atObj.DOwnerName);
            //    excelHelper.SetRowHeight(5, 5, 30);
            //}
            //合同名称
            excelHelper.SetCells(1, 6, 4, atObj.ContractName);
            //施工单位
            if (string.IsNullOrEmpty(atObj.DBankCompanyName))
            {
                excelHelper.SetCells(1, 7, 4, atObj.ContractorName);
            }
            else
            {
                excelHelper.SetCells(1, 7, 4, "施工单位：" + atObj.ContractorName + "\n收款单位："+atObj.DBankCompanyName);
                excelHelper.SetRowHeight(7, 7, 30);
            }
            //资料接收日期
            if (atObj.DocRecTime.HasValue)
            {
                excelHelper.SetCells(1, 7, 7, FormatRecDate(atObj.DocRecTime.Value));
            }
            //收款银行
            excelHelper.SetCells(1, 8, 4, atObj.Bank);
            //收款账号
            excelHelper.SetCells(1, 8, 7, atObj.BankAccount);
        }

        /// <summary>
        /// 输出发票信息
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        /// <returns></returns>
        private static int OutPutInvoice(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper)
        {
            if (atObj.Invoices == null || atObj.Invoices.Count == 0) { return 0; }
            //开始动态新增行
            int startRowIndex = 9;
            int curRowIndex = startRowIndex;
            int addRowCount = 0;
            //本期同时申请的其他笔
            for (int i = 0; i < atObj.Invoices.Count - 1; i++)
            {
                excelHelper.InsertRows(1, curRowIndex + 1, 1);
                excelHelper.SetCells(1, curRowIndex + 1, 4, atObj.Invoices[i].InvoiceNo, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);                
                excelHelper.SetCells(1, curRowIndex + 1, 5, atObj.Invoices[i].InvoiceCode, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                excelHelper.SetCells(1, curRowIndex + 1, 6, atObj.Invoices[i].Amount.ToString(), Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                excelHelper.SetCells(1, curRowIndex + 1, 7, atObj.Invoices[i].IsChecked ? "√" : "");
                excelHelper.SetCells(1, curRowIndex + 1, 8, atObj.Invoices[i].Remark, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                excelHelper.RowAutoFit(curRowIndex + 1);
                curRowIndex++;
                addRowCount++;
            }
            excelHelper.SetCells(1, curRowIndex + 1, 4, atObj.Invoices[atObj.Invoices.Count - 1].InvoiceNo);
            excelHelper.SetCells(1, curRowIndex + 1, 5, atObj.Invoices[atObj.Invoices.Count - 1].InvoiceCode);
            excelHelper.SetCells(1, curRowIndex + 1, 6, atObj.Invoices[atObj.Invoices.Count - 1].Amount.ToString());
            excelHelper.SetCells(1, curRowIndex + 1, 7, atObj.Invoices[atObj.Invoices.Count - 1].IsChecked ? "√" : "");
            excelHelper.SetCells(1, curRowIndex + 1, 8, atObj.Invoices[atObj.Invoices.Count - 1].Remark);
            excelHelper.FontStyle(startRowIndex + 1, 4, curRowIndex + 1, 8, false, false, BaseLibrary.Common.UnderlineStyle.无下划线);
            return addRowCount;
        }

        ///// <summary>
        ///// 设置包含“(X)”的字体为红色
        ///// </summary>
        ///// <param name="excelHelper"></param>
        ///// <param name="rowIndex"></param>
        ///// <param name="columnIndex"></param>
        ///// <param name="cellText"></param>
        //private static void SetRedColor(Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper, int rowIndex, int columnIndex, string cellText)
        //{
        //    //先设置为全部黑色(X)xxx(Y)yyy(Z)zzz
        //    //Excel中字符的索引是从1开始
        //    excelHelper.FontStyle(1, rowIndex, columnIndex, 1, cellText.Length, BaseLibrary.Common.ColorIndex.黑色);
        //    int s = 0, e = 0;
        //    char[] arrChar = cellText.ToCharArray();
        //    for (int i = 0; i < arrChar.Length; i++)
        //    {
        //        if (arrChar[i].Equals('('))
        //        {
        //            s = i;
        //        }
        //        if (arrChar[i].Equals(')'))
        //        {
        //            e = i;
        //        }
        //        if (s != 0 && e != 0 && s < e)
        //        {
        //            excelHelper.FontStyle(1, rowIndex, columnIndex, s + 1, e - s + 1, BaseLibrary.Common.ColorIndex.红色);
        //            s = 0;
        //            e = 0;
        //        }
        //    }
        //}
        
        /// <summary>
        /// 输出“二”
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        /// <returns>动态新增的行数量</returns>
        private static int OutPutPart2(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper, int totalAddCount)
        {
            #region 本合同本期申请资金金额：A

            string cellText = string.Format("本笔申请是本期第({0})笔", atObj.TableNo);
            excelHelper.SetCells(1, 13+totalAddCount, 5, cellText);
            //SetRedColor(excelHelper, 13 + totalAddCount, 5, cellText);
            excelHelper.SetCells(1, 13 + totalAddCount, 8, atObj.Amount_DocRec_S.ToString());
            excelHelper.FontStyle(13 + totalAddCount, 8, 13 + totalAddCount, 8, true, false, BaseLibrary.Common.UnderlineStyle.无下划线);
            //开始动态新增行
            int startRowIndex = 13 + totalAddCount;
            int curRowIndex = startRowIndex;
            int addRowCount = 0;
            //本期同时申请的其他笔
            for (int i = 0; i < atObj.CurOther_C.Count; i++)
            {
                cellText = string.Format("本期同时申请的第({0})笔金额", atObj.CurOther_C[i].TableNo);
                excelHelper.InsertRows(1, curRowIndex + 1, 1);
                excelHelper.MergeCells(1, curRowIndex + 1, 5, curRowIndex + 1, 7, cellText, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                //SetRedColor(excelHelper, curRowIndex + 1, 5, cellText);
                excelHelper.SetCells(1, curRowIndex + 1, 8, atObj.CurOther_C[i].Amount_DocRec_S.ToString());

                curRowIndex++;
                addRowCount++;
            }
            excelHelper.FontStyle(startRowIndex + 1, 8, curRowIndex, 8, false, false, BaseLibrary.Common.UnderlineStyle.无下划线);
            //合并“1、”
            excelHelper.MergeCells(1, startRowIndex, 2, curRowIndex, 2, "1、");
            //合并“本合同本期申请资金金额：A”
            cellText = "本合同本期申请资金金额：A";
            excelHelper.MergeCells(1, startRowIndex, 3, curRowIndex, 4, cellText, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            excelHelper.FontStyle(1, startRowIndex, 3, cellText.Length, 1, true, false, BaseLibrary.Common.UnderlineStyle.无下划线);
            #endregion
            #region 本合同前期投控公司的累计融资金额： B
            startRowIndex = 14+totalAddCount + addRowCount;
            curRowIndex = startRowIndex;
            cellText = string.Format("({0})笔已拨付金额累计", atObj.SummaryAmount.count_C_A);
            excelHelper.SetCells(1, startRowIndex, 5, cellText);
            //SetRedColor(excelHelper, startRowIndex, 5, cellText);
            excelHelper.SetCells(1, startRowIndex, 6, atObj.SummaryAmount.TAmount_C_A == 0 ? "" : atObj.SummaryAmount.TAmount_C_A.ToString());
            if (atObj.SummaryAmount.TAmount_C_A_Date.HasValue && atObj.SummaryAmount.TAmount_C_A !=0)
            {
                excelHelper.SetCells(1, startRowIndex, 7, string.Format("{0:截止到yyyy/M/d}", atObj.SummaryAmount.TAmount_C_A_Date.Value));
            }
            //合同未拨付明细
            for (int i = 0; i < atObj.PastTime_C_NA.Count; i++)
            {
                excelHelper.InsertRows(1, curRowIndex + 1, 1);
                excelHelper.SetCells(1, curRowIndex + 1, 6, atObj.PastTime_C_NA[i].ActiveAmount == 0 ? "" : atObj.PastTime_C_NA[i].ActiveAmount.ToString());
                excelHelper.SetCells(1, curRowIndex + 1, 7, atObj.PastTime_C_NA[i].AuditTableCode.ToString());
                curRowIndex++;
                addRowCount++;
            }
            //合并“2、”
            excelHelper.MergeCells(1, startRowIndex, 2, curRowIndex, 2, "2、");
            //合并“本合同前期投控公司的累计融资金额：B”
            cellText = "本合同前期投控公司的累计融资金额：B";
            excelHelper.MergeCells(1, startRowIndex, 3, curRowIndex, 4, cellText, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            excelHelper.FontStyle(1, startRowIndex, 3, cellText.Length, 1, true, false, BaseLibrary.Common.UnderlineStyle.无下划线);
            //合并“合同未拨付明细”
            cellText = string.Format("({0})笔未拨付金额明细", atObj.SummaryAmount.count_C_NA);
            excelHelper.MergeCells(1, startRowIndex + 1, 5, curRowIndex, 5, cellText, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            //SetRedColor(excelHelper, startRowIndex + 1, 5, cellText);
            //合并合同已拨付加未拨付
            excelHelper.MergeCells(1, startRowIndex, 8, curRowIndex, 8, atObj.SummaryAmount.TAmount_C_NA_A.ToString(), Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            #endregion
            #region 本合同前期加本期融资金额累计： C=A+B
            excelHelper.MergeCells(1, 15 + totalAddCount + addRowCount, 5, 15 + totalAddCount + addRowCount, 7, "", Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            excelHelper.SetCells(1, 15 + totalAddCount + addRowCount, 8, atObj.SummaryAmount.TAmount_C.ToString());
            #endregion
            #region 本项目本期申请资金合计： D（本项目所有合同本期资金申请之和)
            startRowIndex = 16 + totalAddCount + addRowCount;
            curRowIndex = startRowIndex;
            excelHelper.SetCells(1, startRowIndex, 6, atObj.CurOther_P[0].Amount_DocRec_S.ToString());
            excelHelper.SetCells(1, startRowIndex, 7, atObj.CurOther_P[0].AuditTableCode);
            //本项目本期所有记录
            for (int i = 1; i < atObj.CurOther_P.Count; i++)
            {
                excelHelper.InsertRows(1, curRowIndex + 1, 1);
                excelHelper.SetCells(1, curRowIndex + 1, 6, atObj.CurOther_P[i].Amount_DocRec_S == 0 ? "" : atObj.CurOther_P[i].Amount_DocRec_S.ToString());
                excelHelper.SetCells(1, curRowIndex + 1, 7, atObj.CurOther_P[i].AuditTableCode);
                curRowIndex++;
                addRowCount++;
            }
            //合并“4、”
            excelHelper.MergeCells(1, startRowIndex, 2, curRowIndex, 2, "4、", Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            //合并“本项目本期申请资金合计：D”
            excelHelper.MergeCells(1, startRowIndex, 3, curRowIndex, 4,string.Format( "本{0}项目本期申请资金合计：D\n（本项目所有合同本期资金申请之和)",(atObj.TableType=="A" ? "" : "分")), Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            excelHelper.FontStyle(1, startRowIndex, 3, cellText.IndexOf("D") + 1, 1, true, false, BaseLibrary.Common.UnderlineStyle.无下划线);
            //合并“已报审”
            cellText = string.Format("本{0}项目已报审({1})个合同，本期有({2})个合同申请({3})笔资金",(atObj.TableType=="A" ? "" : "分"), atObj.SummaryAmount.count_PC_All, atObj.SummaryAmount.count_PC, atObj.SummaryAmount.count_PT);
            excelHelper.MergeCells(1, startRowIndex, 5, curRowIndex, 5, cellText, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            //SetRedColor(excelHelper, startRowIndex, 5, cellText);
            //合并本期所有
            excelHelper.MergeCells(1, startRowIndex, 8, curRowIndex, 8, atObj.SummaryAmount.TAmount_PT.ToString(), Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            #endregion
            #region 本项目前期投控公司的累计融资金额： E
            //项目已拨付金额
            cellText = string.Format("({0})笔已拨付金额累计", atObj.SummaryAmount.count_P_A);
            startRowIndex = 17+totalAddCount + addRowCount;
            curRowIndex = startRowIndex;
            excelHelper.SetCells(1, curRowIndex, 5, cellText);
            //SetRedColor(excelHelper, curRowIndex, 5, cellText);
            excelHelper.SetCells(1, curRowIndex, 6, atObj.SummaryAmount.TAmount_P_A == 0 ? "" : atObj.SummaryAmount.TAmount_P_A.ToString());
            if (atObj.SummaryAmount.TAmount_P_A_Date.HasValue && atObj.SummaryAmount.TAmount_P_A != 0)
            {
                excelHelper.SetCells(1, curRowIndex, 7, string.Format("截止到{0:yyyy/M/d}", atObj.SummaryAmount.TAmount_P_A_Date.Value));
            }
            //项目未拨付
            for (int i = 0; i < atObj.PastTime_P_NA.Count; i++)
            {
                excelHelper.InsertRows(1, curRowIndex + 1, 1);
                excelHelper.SetCells(1, curRowIndex + 1, 6, atObj.PastTime_P_NA[i].ActiveAmount == 0 ? "" : atObj.PastTime_P_NA[i].ActiveAmount.ToString());
                excelHelper.SetCells(1, curRowIndex + 1, 7, atObj.PastTime_P_NA[i].AuditTableCode.ToString());
                curRowIndex++;
                addRowCount++;
            }
            //合并“5、”
            excelHelper.MergeCells(1, startRowIndex, 2, curRowIndex, 2, "5、");
            //合并“本项目前期投控公司的累计融资金额： E”
            cellText = string.Format("本{0}项目前期投控公司的累计融资金额： E\n（2011年度投控拨付的本{1}项目所有合同前期资金之和）", (atObj.TableType == "A" ? "" : "分"), (atObj.TableType == "A" ? "" : "分"));
            excelHelper.MergeCells(1, startRowIndex, 3, curRowIndex, 4, cellText, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            excelHelper.FontStyle(1, startRowIndex, 3, cellText.IndexOf("E") + 1, 1, true, false, BaseLibrary.Common.UnderlineStyle.无下划线);
            cellText = string.Format("({0})笔未拨付金额明细", atObj.SummaryAmount.count_P_NA);
            excelHelper.MergeCells(1, startRowIndex + 1, 5, curRowIndex, 5, cellText, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            //SetRedColor(excelHelper, startRowIndex + 1, 5, cellText);
            //合并项目未拨付加已拨付
            excelHelper.MergeCells(1, startRowIndex, 8, curRowIndex, 8, atObj.SummaryAmount.TAmount_P_NA_A.ToString(), Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            #endregion
            #region 本项目本期加前期融资资金累计 F=D+E
            excelHelper.SetCells(1, 18+totalAddCount + addRowCount, 8, atObj.SummaryAmount.TAmount_P.ToString());
            excelHelper.FontStyle(1, 18 + totalAddCount + addRowCount, 8, 18 + totalAddCount + addRowCount, 8, true, false, BaseLibrary.Common.UnderlineStyle.无下划线);
            excelHelper.MergeCells(1, 18 + totalAddCount + addRowCount, 5, 18 + totalAddCount + addRowCount, 7, "");
            #endregion
            #region 其他各分项目数据
            if (atObj.TableType != "A")
            {
                startRowIndex = 22 + totalAddCount + addRowCount;
                curRowIndex = startRowIndex;
                //Modify by 2012-11-29 有时可能是第一笔有项目的单，可能没有其他分项目的信息
                if (atObj.CurOther_Split != null)
                {
                    for (int i = 0; i < atObj.CurOther_Split.Count; i++)
                    {
                        excelHelper.InsertRows(1, curRowIndex, 1);
                        excelHelper.SetCells(1, curRowIndex, 2, atObj.CurOther_Split[i].ProjectSN);
                        excelHelper.MergeCells(1, curRowIndex, 3, curRowIndex, 4, atObj.CurOther_Split[i].ProjectName, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                        excelHelper.SetCells(1, curRowIndex, 5, atObj.CurOther_Split[i].TAmount_A.ToString(), Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                        excelHelper.SetCells(1, curRowIndex, 6, atObj.CurOther_Split[i].TAmount_NA.ToString(), Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                        excelHelper.SetCells(1, curRowIndex, 7, atObj.CurOther_Split[i].Amount_S.ToString(), Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                        excelHelper.SetCells(1, curRowIndex, 8, atObj.CurOther_Split[i].TotalAmount.ToString(), Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                        curRowIndex++;
                        addRowCount++;
                    }
                }
                //excelHelper.SetAlignment(1, startRowIndex, 5, startRowIndex + addRowCount, 8, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                excelHelper.SetCells(1, 22 + totalAddCount + addRowCount, 8, atObj.SummaryAmount.TAmount_SumP.ToString());
            }
            #endregion

            return addRowCount;
        }

        private static void OutPutPart2Split(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper)
        {
            
        }

        /// <summary>
        /// 输出“三”
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        /// <param name="totalAddCount"></param>
        private static void OutPutPart3(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper, int totalAddCount)
        {
            int startRowIndex = 22;
            if (atObj.TableType != "A") { startRowIndex = 26; }
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 6, atObj.AuditCase.PD1);
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 8, atObj.AuditCase.PD1Opinion);
            excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 6, atObj.AuditCase.PD2);
            excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 8, atObj.AuditCase.PD2Opinion);
        }
        /// <summary>
        /// 输出“四”
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        /// <param name="totalAddCount"></param>
        private static void OutPutPart4(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper, int totalAddCount)
        {
            int startRowIndex = 26;
            if (atObj.TableType != "A") { startRowIndex = 30; }
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 6, atObj.AuditCase.CD);
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 8, atObj.AuditCase.CDOpinion);
        }
        /// <summary>
        /// 输出“五”
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        /// <param name="totalAddCount"></param>
        private static void OutPutPart5(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper, int totalAddCount)
        {
            int startRowIndex = 29;
            if (atObj.TableType != "A") { startRowIndex = 33; }
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 6, atObj.Amount_CZLJ.ToString());
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 8, atObj.AuditCase.ZDOpinion);
            if (atObj.TableType == "A")
            {
                excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 6, atObj.Amount_ZBJ.ToString());
            }
            else
            {
                excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 6, atObj.Amount_SumZBJ.ToString());
            }
            //excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 6, atObj.AuditCase.ZD);
            //excelHelper.SetCells(1, startRowIndex + 2 + totalAddCount, 6, atObj.Amount_SumZBJ_Add.ToString());
            excelHelper.SetCells(1, startRowIndex + 2 + totalAddCount, 6, atObj.Amount_ZBJ_Add.ToString());
        }
        /// <summary>
        /// 输出“六”
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        /// <param name="totalAddCount"></param>
        private static void OutPutPart6(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper, int totalAddCount)
        {
            int startRowIndex = 34;
            if (atObj.TableType != "A") { startRowIndex = 38; }
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 6, atObj.Amount_GS.ToString());
            //if (atObj.TableType != "A")
            //{
            //    excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 6, atObj.Amount_SumGS.ToString());
            //}
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 8, atObj.AuditCase.ForPPriceOpinion);
            if (atObj.TableType == "A")
            {
                excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 6, atObj.Amount_ZBJ.ToString());
            }
            else if (atObj.TableType == "B")
            {
                excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 6, atObj.Amount_ZBJ.ToString());
            }
            else if (atObj.TableType == "C")
            {
                excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 6, atObj.Amount_SumZBJ.ToString());
            }
            if (atObj.TableType == "A")
            {
                excelHelper.SetCells(1, startRowIndex + 2 + totalAddCount, 6, atObj.SummaryAmount.PP_GS);
                excelHelper.SetCells(1, startRowIndex + 3 + totalAddCount, 7, string.Format("{0:P}", atObj.SummaryAmount.PP_GSResult));
            }
            else
            {
                excelHelper.SetCells(1, startRowIndex + 2 + totalAddCount, 6, atObj.SummaryAmount.PP_GS);
                excelHelper.SetCells(1, startRowIndex + 3 + totalAddCount, 7, string.Format("{0:P}", atObj.SummaryAmount.PP_GSResult));
            }

            //Add by 2012-9-25 增加 "本项目项下全部合同总价金额累计 U" "合同总价金额与项目总投资匹配关系核算（U不超过本项目总概算批复金额 T)"
            excelHelper.SetCells(1, startRowIndex + 4 + totalAddCount, 6, atObj.SummaryAmount.TAmount_U.ToString());
            excelHelper.SetCells(1, startRowIndex + 5 + totalAddCount, 6, atObj.SummaryAmount.PP_TAmount_U_T);
            excelHelper.SetCells(1, startRowIndex + 6 + totalAddCount, 7, string.Format("{0:P}", atObj.SummaryAmount.PP_TAmount_U_T_Result));

        }
        /// <summary>
        /// 输出“七”
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        /// <param name="totalAddCount"></param>
        /// <returns>动态新增的行数</returns>
        private static int OutPutPart7(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper,int totalAddCount)
        {
            int addRowCount = 0;
            int startRowIndex = 43 + totalAddCount;// 40 + totalAddCount;
            if (atObj.TableType != "A") {
                startRowIndex = 47 + totalAddCount;// 44 + totalAddCount; 
            }
            int curRowIndex = startRowIndex;
            //excelHelper.SetCells(1, startRowIndex, 6, atObj.YearPlans[0].Amount.ToString());
            string planText = "";
            string cellText = ""; //string.Format("本项目{0}年度投资计划 P1", atObj.YearPlans[0].TheYear);
            //if (!string.IsNullOrEmpty(atObj.YearPlans[0].DocNo))
            //{
            //    cellText += string.Format("\n（以{0}号文件中的{1}年融资计划为准）", atObj.YearPlans[0].DocNo, atObj.YearPlans[0].TheYear);
            //}
            //planText = "P1";
            //excelHelper.SetCells(1, startRowIndex, 3, cellText);
            for (int i = 0; i < atObj.YearPlans.Count; i++)
            {
                excelHelper.InsertRows(1, curRowIndex, 1);
                excelHelper.SetCells(1, curRowIndex, 2, (i + 1).ToString() + "、");
                cellText = string.Format("本项目{0}年度投资计划 P{1}", atObj.YearPlans[i].TheYear, i + 1);
                if (!string.IsNullOrEmpty(atObj.YearPlans[i].DocNo))
                {
                    cellText += string.Format("\n（以{0}号文件中的{1}年融资计划为准）", atObj.YearPlans[i].DocNo, atObj.YearPlans[i].TheYear);
                }
                excelHelper.MergeCells(1, curRowIndex , 3, curRowIndex , 5, cellText, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                excelHelper.MergeCells(1, curRowIndex , 6, curRowIndex , 7, atObj.YearPlans[i].Amount.ToString(), Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
                if (planText != "") { planText += "+"; }
                planText += "P" + (i + 1).ToString();
                curRowIndex++;
                addRowCount++;
            }
            excelHelper.FontStyle(startRowIndex, 2, startRowIndex + addRowCount, 7, false, false, BaseLibrary.Common.UnderlineStyle.无下划线);
            excelHelper.SetCells(1, startRowIndex +addRowCount, 2, (atObj.YearPlans.Count + 1).ToString() + "、");
            excelHelper.SetCells(1, startRowIndex  + addRowCount , 3, "累计年度投资计划 P=" + planText);
            excelHelper.SetCells(1, startRowIndex + addRowCount , 6, atObj.SummaryAmount.TAmount_Plan.ToString());
            excelHelper.SetCells(1, startRowIndex + 1 + addRowCount , 2, (atObj.YearPlans.Count + 2).ToString() + "、");
            excelHelper.SetCells(1, startRowIndex + 1 + addRowCount , 6, atObj.SummaryAmount.PP_Plan);
            excelHelper.SetCells(1, startRowIndex + 2 + addRowCount , 7, string.Format("{0:P}", atObj.SummaryAmount.PP_PlanResult));
            excelHelper.MergeCells(1, startRowIndex, 8, startRowIndex + addRowCount + 2, 8, atObj.AuditCase.ForPlanOpinion, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter, Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter);
            excelHelper.FontStyle(startRowIndex, 8, startRowIndex + addRowCount + 2, 8, false, false, BaseLibrary.Common.UnderlineStyle.无下划线);
            return addRowCount;
        }
        /// <summary>
        /// 输出“八”
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        /// <param name="totalAddCount"></param>
        private static void OutPutPart8(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper, int totalAddCount)
        {
            int startRowIndex = 48;// 45;
            if (atObj.TableType != "A") {
                startRowIndex = 52;// 49; 
            }
            //excelHelper.SetCells(1, startRowIndex + totalAddCount, 6, atObj.Amount_SumGKLoan.ToString());
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 6, atObj.Amount_GKLoan.ToString());
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 8, atObj.AuditCase.ForLoanOpinion);
            excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 6, atObj.SummaryAmount.PP_PGK);
            excelHelper.SetCells(1, startRowIndex + 2 + totalAddCount, 7, string.Format("{0:P}", atObj.SummaryAmount.PP_PGKResult));
            excelHelper.SetCells(1, startRowIndex + 3 + totalAddCount, 6, atObj.Amount_PSTK.ToString());
            excelHelper.SetCells(1, startRowIndex + 4 + totalAddCount, 6, atObj.SummaryAmount.PP_PLoanTK);
            excelHelper.SetCells(1, startRowIndex + 5 + totalAddCount, 7, string.Format("{0:P}", atObj.SummaryAmount.PP_PLoanTKResult));
        }
        /// <summary>
        /// 输出“九”
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        /// <param name="totalAddCount"></param>
        private static void OutPutPart9(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper, int totalAddCount)
        {
            int startRowIndex = 56;// 53;
            if (atObj.TableType != "A") {
                startRowIndex = 60;// 57; 
            }
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 6, atObj.Amount_C_S.ToString());
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 8, atObj.AuditCase.ForCPriceOpinion);
            excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 6, atObj.TAmount_C_A_S.ToString());
            excelHelper.SetCells(1, startRowIndex + 2 + totalAddCount, 7, string.Format("{0:P}", atObj.SummaryAmount.TAmount_C_P));
            excelHelper.SetCells(1, startRowIndex + 3 + totalAddCount, 6, atObj.SummaryAmount.TAmount_C_T.ToString());
            excelHelper.SetCells(1, startRowIndex + 4 + totalAddCount, 6, atObj.SummaryAmount.PP_CPrice);
            excelHelper.SetCells(1, startRowIndex + 5 + totalAddCount, 7, string.Format("{0:P}", atObj.SummaryAmount.PP_CPriceResult));
            excelHelper.SetCells(1, startRowIndex + 6 + totalAddCount, 6, atObj.Amount_S.ToString());
            excelHelper.SetCells(1, startRowIndex + 7 + totalAddCount, 7, string.Format("{0:P}", atObj.SummaryAmount.PP_CPrice_Amount_S_Result));
        }
        /// <summary>
        /// 输出“十”
        /// </summary>
        /// <param name="atObj"></param>
        /// <param name="excelHelper"></param>
        /// <param name="totalAddCount"></param>
        private static void OutPutPart10(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper, int totalAddCount)
        {
            int startRowIndex = 66;// 63;
            if (atObj.TableType != "A") {
                startRowIndex = 70;// 67; 
            }
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 6, atObj.AuditCase.ForProgress);
            excelHelper.SetCells(1, startRowIndex + totalAddCount, 8, atObj.AuditCase.ForProgressOpinion);
        }

        private static void OutPutPartWorkflow(Bu_AuditTable atObj, Honestysoft.BaseLibrary.Common.ExcelHelper excelHelper, int totalAddCount)
        {
            int startRowIndex = 68;// 65;
            if (atObj.TableType != "A") {
                startRowIndex = 72;// 69; 
            }
            Honestysoft.Workflow.BusinessFacade.WFApply.Tracker ITracker = new Workflow.BusinessFacade.WFApply.Tracker();
            List<Honestysoft.Workflow.Model.WFOpinion> lsOpinion = ITracker.GetOpinions(((int)EnumItem.WFBill.AuditTable).ToString(), atObj.ID);
            if (lsOpinion != null && lsOpinion.Count > 0)
            {
                List<Honestysoft.Workflow.Model.WFOpinion> lsTempOpinions = null;
                lsTempOpinions = lsOpinion.FindAll((Honestysoft.Workflow.Model.WFOpinion find) => find.ActTemplate.ActTempSerial.HasValue && find.ActTemplate.ActTempSerial.Value == 4);
                int serial = 0;
                foreach (Honestysoft.Workflow.Model.WFOpinion item in lsTempOpinions)
                {
                    if (item.SignSerial > serial) { serial = item.SignSerial; }
                }
                Honestysoft.Workflow.Model.WFOpinion opinion = lsTempOpinions.Find((Honestysoft.Workflow.Model.WFOpinion find) => find.SignSerial == serial);
                if (opinion != null)
                {
                    excelHelper.SetCells(1, startRowIndex + totalAddCount, 8, opinion.TranTime.HasValue ? opinion.TranTime.Value.ToString("yyyy-MM-dd") : "");
                    excelHelper.SetCells(1, startRowIndex + 2 + totalAddCount, 8, opinion.TranTime.HasValue ? opinion.TranTime.Value.ToString("yyyy-MM-dd") : "");
                    excelHelper.SetCells(1, startRowIndex + 4 + totalAddCount, 8, opinion.TranTime.HasValue ? opinion.TranTime.Value.ToString("yyyy-MM-dd") : "");
                }
                lsTempOpinions = lsOpinion.FindAll((Honestysoft.Workflow.Model.WFOpinion find) => find.ActTemplate.ActTempSerial.HasValue && find.ActTemplate.ActTempSerial.Value == 3);
                serial = 0;
                foreach (Honestysoft.Workflow.Model.WFOpinion item in lsTempOpinions)
                {
                    if (item.SignSerial > serial) { serial = item.SignSerial; }
                }
                opinion = lsTempOpinions.Find((Honestysoft.Workflow.Model.WFOpinion find) => find.SignSerial == serial);
                if (opinion != null)
                {
                    excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 4, opinion.Opinion);
                }
                lsTempOpinions = lsOpinion.FindAll((Honestysoft.Workflow.Model.WFOpinion find) => find.ActTemplate.ActTempSerial.HasValue && find.ActTemplate.ActTempSerial.Value == 4);
                serial = 0;
                foreach (Honestysoft.Workflow.Model.WFOpinion item in lsTempOpinions)
                {
                    if (item.SignSerial > serial) { serial = item.SignSerial; }
                }
                opinion = lsTempOpinions.Find((Honestysoft.Workflow.Model.WFOpinion find) => find.SignSerial == serial);
                if (opinion != null)
                {
                    excelHelper.SetCells(1, startRowIndex + 3 + totalAddCount, 4, opinion.Opinion);
                }
                //不能用 SignSerial 来判断环境，因为可能存在退回的记录。改为用流程配置中定义的环节序号来判断（必须取最大记录）                    
                //foreach (Honestysoft.Workflow.Model.WFOpinion item in lsOpinion)
                //{
                //    if (item.SignSerial == 1) { continue; }
                //    if (item.SignSerial == 2)
                //    {
                //        excelHelper.SetCells(1, startRowIndex + totalAddCount, 8, item.TranTime.HasValue ? item.TranTime.Value.ToString("yyyy-MM-dd") : "");
                //        excelHelper.SetCells(1, startRowIndex + 2 + totalAddCount, 8, item.TranTime.HasValue ? item.TranTime.Value.ToString("yyyy-MM-dd") : "");
                //        excelHelper.SetCells(1, startRowIndex + 4 + totalAddCount, 8, item.TranTime.HasValue ? item.TranTime.Value.ToString("yyyy-MM-dd") : "");
                //    }
                //    else if (item.SignSerial == 3)
                //    {
                //        excelHelper.SetCells(1, startRowIndex + 1 + totalAddCount, 4, item.Opinion);
                //    }
                //    else if (item.SignSerial == 4)
                //    {
                //        excelHelper.SetCells(1, startRowIndex + 3 + totalAddCount, 4, item.Opinion);
                //    }
                //}
            }
            //1.审核日期
            //2.审核小组意见
            //3.审核组长审核日期
            //4.审核会议意见
            //5.公司领导审核日期
        }
    }

    

    ///  
    /// 本类实现阿拉伯数字到大写中文的转换 
    /// 该类没有对非法数字进行判别,请事先自己判断数字是否合法 
    ///  
    public class ChineseNum
    {
        //小写转大写 
        public static string GetChineseNum(string p_num)
        {
            ChineseNum cn = new ChineseNum();
            return cn.NumToChn(p_num);
        }
        //小写金额转大写金额 
        //public static string GetUpperMoney(double p_Money)
        //{
        //    ChineseNum cn = new ChineseNum();
        //    return cn.GetMoneyChinese(p_Money);
        //}
        //转换数字 
        private char CharToNum(char x)
        {
            string stringChnNames = "零一二三四五六七八九";
            string stringNumNames = "0123456789";
            return stringChnNames[stringNumNames.IndexOf(x)];
        }
        //转换万以下整数 
        private string WanStrToInt(string x)
        {
            string[] stringArrayLevelNames = new string[4] { "", "十", "百", "千" };
            string ret = "";
            int i;
            for (i = x.Length - 1; i >= 0; i--)
                if (x[i] == '0')
                {
                    ret = CharToNum(x[i]) + ret;
                }
                else
                {
                    ret = CharToNum(x[i]) + stringArrayLevelNames[x.Length - 1 - i] + ret;
                }
            while ((i = ret.IndexOf("零零")) != -1)
            {
                ret = ret.Remove(i, 1);
            }
            if (ret[ret.Length - 1] == '零' && ret.Length > 1)
            {
                ret = ret.Remove(ret.Length - 1, 1);
            }
            if (ret.Length >= 2 && ret.Substring(0, 2) == "一十")
            {
                ret = ret.Remove(0, 1);
            }
            return ret;
        }
        //转换整数 
        private string StrToInt(string x)
        {
            int len = x.Length;
            string ret, temp;
            if (len <= 4)
            {
                ret = WanStrToInt(x);
            }
            else if (len <= 8)
            {
                ret = WanStrToInt(x.Substring(0, len - 4)) + "万";
                temp = WanStrToInt(x.Substring(len - 4, 4));
                if (temp.IndexOf("千") == -1 && temp != "")
                    ret += "零" + temp;
                else
                    ret += temp;
            }
            else
            {
                ret = WanStrToInt(x.Substring(0, len - 8)) + "亿";
                temp = WanStrToInt(x.Substring(len - 8, 4));
                if (temp.IndexOf("千") == -1 && temp != "")
                {
                    ret += "零" + temp;
                }
                else
                {
                    ret += temp;
                }
                ret += "万";
                temp = WanStrToInt(x.Substring(len - 4, 4));
                if (temp.IndexOf("千") == -1 && temp != "")
                {
                    ret += "零" + temp;
                }
                else
                {
                    ret += temp;
                }
            }
            int i;
            if ((i = ret.IndexOf("零万")) != -1)
            {
                ret = ret.Remove(i + 1, 1);
            }
            while ((i = ret.IndexOf("零零")) != -1)
            {
                ret = ret.Remove(i, 1);
            }
            if (ret[ret.Length - 1] == '零' && ret.Length > 1)
            {
                ret = ret.Remove(ret.Length - 1, 1);
            }
            return ret;
        }
        //转换小数 
        private string StrToDouble(string x)
        {
            string ret = "";
            for (int i = 0; i < x.Length; i++)
            {
                ret += CharToNum(x[i]);
            }
            return ret;
        }
        private string NumToChn(string x)
        {
            if (x.Length == 0)
            {
                return "";
            }
            string ret = "";
            if (x[0] == '-')
            {
                ret = "负";
                x = x.Remove(0, 1);
            }
            if (x[0].ToString() == ".")
            {
                x = "0" + x;
            }
            if (x[x.Length - 1].ToString() == ".")
            {
                x = x.Remove(x.Length - 1, 1);
            }
            if (x.IndexOf(".") > -1)
            {
                ret += StrToInt(x.Substring(0, x.IndexOf("."))) + "点" + StrToDouble(x.Substring(x.IndexOf(".") + 1));
            }
            else
            {
                ret += StrToInt(x);
            }
            return ret;
        }
    }


    /// <summary>
    /// 汇总表
    /// </summary>
    public class AuditSummaryUtils
    {
        /// <summary>
        /// 发改委支付汇总表Session的ID
        /// </summary>
        public const string FWGSessionID = "6CF2604C-01B4-4B17-8CD3-20322D13C8FB";

        /// <summary>
        /// 本次操作的支付汇总表（发改委）的Session
        /// </summary>
        public static Bu_AuditTable_FGW ThisTimeFGWSession
        {
            get
            {
                if (HttpContext.Current.Session[FWGSessionID] == null) { return null; }
                return HttpContext.Current.Session[FWGSessionID] as Bu_AuditTable_FGW;
            }
            set
            {
                HttpContext.Current.Session[FWGSessionID] = value;
            }
        }
    }
}